package com.itheima.d3_arraylist;

import java.util.ArrayList;

public class ArrayListDemo3 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student stu1 = new Student("小王", 18);
        Student stu2 = new Student("小张", 19);
        list.add(stu1);
        list.add(stu2);
        //遍历集合
        for (int i = 0; i < list.size(); i++){
            //i是索引 list.get(i)就是里面的元素
            Student s = list.get(i);
            System.out.println(s.getName() + " " + s.getAge());
        }
    }
}
